<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>授课医生</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
	<link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
	<link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
		rel="stylesheet" />
	<script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>
	<style>
		#Left {
			width: 40%;
			position: fixed;
			left: 0;
			top: 0;
			bottom: 0;
			background: #fff;
			border-right: 1px solid #ccc;
			box-shadow: #ccc 0 2px 4px;
			overflow: auto;
		}

		#MainRight {
			margin-left: 40%;
			overflow: hidden;
			background: #fff;
			border-right: 1px solid #ccc;
			box-shadow: #ccc 0 2px 4px;
		}

		.top1 {
			margin-top: 75px;
		}
	</style>
</head>

<body>
	<div id="Left">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
			<legend>选择医生</legend>
		</fieldset>
		<div class="layui-fluid">
			<div class="layui-card">
				<div class="layui-form layui-card-header layuiadmin-card-header-auto">
					<div class="layui-input-inline">
						<label class="layui-form-label">医生姓名：</label>
						<div class="layui-input-inline">
							<input type="text" name="DocName" id="DocName" placeholder="请输入姓名查询" autocomplete="off"
								class="layui-input">
						</div>
					</div>
					<div class="layui-input-inline">
						<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-app-front-search"
							id="btnSearch">
							<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
						</button>
					</div>
				</div>

				<div class="layui-card-body">
					<table id="docTable" lay-filter="docTable"></table>
				</div>
			</div>
		</div>
	</div>
	<div id="MainRight">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
			<legend>已选医生</legend>
		</fieldset>
		<div class="layui-fluid">
			<div class="layui-card">
				<!-- <div class="layui-form layui-card-header layuiadmin-card-header-auto">
				</div> -->

				<div class="layui-card-body top1">
					<table id="selecteddocTable" lay-filter="selecteddocTable"></table>
				</div>
			</div>
		</div>
	</div>
	<script type="text/html" id="option1">
		<a class="layui-btn layui-btn-sm" lay-event="select">选择</a>
	</script>
	<script type="text/html" id="option2">
		<a class="layui-btn layui-btn-sm  layui-btn-danger" lay-event="remove">移除</a>
	</script>
</body>

</html>

<script>
	layui.config({
		base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	});

	layui.define(['index', 'layer', 'form', 'element', 'table', 'upload', 'laytpl'], function () {
		var layer = layui.layer;
		var form = layui.form;
		var element = layui.element;
		var table = layui.table;
		var $ = layui.$;
		var admin = layui.admin;
		var setter = layui.setter;
		var upload = layui.upload;
		var laytpl = layui.laytpl;


		var controller = {
			data: {
				model: {},
				docTable: {},
				seldocTable: {},
			},
			//初始化页面
			initpage: function () {
				var self = this;
				self.data.model = parent.modelData;
				self.initevent(function () {
					self.doctableLoad();
					self.selectedDoctableLoad();
				});

			},
			getbaseurl: function (fun) {
				var url = "/lowcode/APP20210908194005415/live/?view=layui&fun=" + fun;
				return url;
			},
			//初始化事件
			initevent: function (func) {
				var self = this;				
				var flag = true
				//监听行工具事件
				table.on('tool(docTable)', function (obj) {  //tool是工具条事件名，table原始容器的属性
					var data = obj.data;//当前行数据
					var layEvent = obj.event;//获得lay-event的值
					if (layEvent === "select") {
						if(flag==false){
							return
						}
						flag = false
						setTimeout(() => {
							flag = true
						}, 1000);
						list2 = table.cache.selecteddocTable;
						if (list2) {
							for (var i = 0; i < list2.length; i++) {
								if (data.EmpId == list2[i].EmpId) {
									layer.alert('此医生已开通直播间', { icon: 2 });
									return;
								}
							}
						}
						self.createroom(data);
						
					}
				});
				table.on('tool(selecteddocTable)', function (obj) {  //tool是工具条事件名，table原始容器的属性
					var data = obj.data;//当前行数据
					var layEvent = obj.event;//获得lay-event的值
					if (layEvent === "remove") {
						if(flag==false){
							return
						}
						flag = false
						setTimeout(() => {
							flag = true
						}, 1000);
						self.removeroom(data);
					}
				});

				form.on("submit(LAY-app-front-search)",
					function (data) {
						self.doctableLoad();
					});

				var url = this.getbaseurl("LiveCourse.getbaseinfo");
				admin.req({
					url: url,  //控制器名称，方法名称
					data: {},
					done: function (res) {
						console.log(res);
						self.data.baseinfo = res.data;
						console.log(self.data.baseinfo.WorkId)
						console.log(self.data.baseinfo.apiGateway)
						if (func) {
							func();
						}
					}
				});
			},
			createroom: function (row) {
				var self = this
				// var mod = {
				// 	CourseId: self.data.model.CourseId,
				// 	EmpId: row.EmpId,
				// 	WorkId: row.WorkId,
				// 	RoomId: '',
				// 	DocName: row.DocName,
				// 	DeptId: row.DeptId,
				// 	DeptNames: row.DeptNames,
				// 	DocLevelId: row.DocLevelId,
				// 	DocLevel: '',
				// };
				row.CourseId = self.data.model.CourseId
				admin.req({
					url: self.data.baseinfo.apiGateway + "/live/v1/Live/CreateLiveRoom",
					method: 'post',
					contentType: 'application/json',
					data: JSON.stringify(row),
					done: function (res) {
						console.log(res);
						if (res.code == 0) {
							layer.msg('操作成功')
							self.selectedDoctableLoad();
						}
					}
				});
			},
			removeroom: function (row) {
				var self = this
				admin.req({
					url: self.data.baseinfo.apiGateway + "/live/v1/Live/RemoveLiveRoom",
					method: 'post',
					contentType: 'application/json',
					data: JSON.stringify(row),
					done: function (res) {
						console.log(res);
						if (res.code == 0) {
							layer.msg('操作成功')
							self.selectedDoctableLoad();
						}
					}
				});
			},
			doctableLoad: function () {
				var self = this;
				var Name = $("#DocName").val();
				self.data.docTable = table.render({
					elem: "#docTable",
					where: {
						workId: self.data.baseinfo.WorkId,
						deptId: 0,
						mpUserId: '',
						searchkey: Name,
						changjing: 1
					},
					toolbar: '',
					url: self.data.baseinfo.apiGateway + "/self-patient/v1/Doctor/GetDocListAndStatus",
					parseData: function (res) { //res 即为原始返回的数据
						return {
							"code": res.code, //解析接口状态
							"msg": res.msg, //解析提示文本
							"count": res.data.totalRecord, //解析数据长度
							"data": res.data.doctorList //解析数据列表
						};
					},
					height: "full-200",
					size: '10',
					page: true, //开启分页 
					loading: true,
					cols: [
						[
							{ field: 'DocName', title: '医生姓名', width: '25%' },
							{ field: 'DocDeptName', title: '所属科室', width: '25%' },
							{ field: 'DocLevel', title: '级别', width: '25%' },
							{ field: 'operation', title: '操作', toolbar: '#option1', width: '25%', fixed: 'right' }
						]
					],
					done: function (res) {
						console.log(res)
						self.data.tabledata = res.data
					}
				});
			},
			selectedDoctableLoad: function () {
				var self = this;
				var CourseId = self.data.model.CourseId;
				self.data.seldocTable = table.render({
					elem: "#selecteddocTable",
					where: {
						workId: self.data.baseinfo.WorkId,
						CourseId: CourseId
					},
					toolbar: '',
					url: self.getbaseurl("LiveCourse.getcourseemp"),
					parseData: function (res) { //res 即为原始返回的数据
						return {
							"code": res.code, //解析接口状态
							"msg": res.msg, //解析提示文本
							"count": res.data.data.length, //解析数据长度
							"data": res.data.data //解析数据列表
						};
					},
					height: "full-200",
					size: '10',
					page: false, //开启分页 
					loading: true,
					cols: [
						[
							{ field: 'DocName', title: '医生姓名', width: '25%' },
							{ field: 'DeptNames', title: '所属科室', width: '25%' },
							{ field: 'DocLevel', title: '级别', width: '25%' },
							{ field: 'operation', title: '操作', toolbar: '#option2', width: '25%', fixed: 'right' }
						]
					],
					done: function (res) {
						console.log(res)
						self.data.tabledata = res.data
					}
				});
			},
		}

		/*
		* 入口
		*/
		controller.initpage();
	});

</script>